home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dbcexe / errorhan.cls < prev    next >
Encoding:
Visual Basic class definition  |  1997-07-26  |  3.3 KB  |  92 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "ErrorHandler"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. Public Function FatalError(ErrorNum As Integer, Source As String)
  13. Attribute FatalError.VB_UserMemId = 0
  14.  
  15. '***When calling this sub from a form use this syntax: _
  16.     If not oError(Err.Number, 'Name of Form and Sub' in quotes) Then Resume
  17.         
  18.     Dim sMsg As String 'Holds the message to be displayed in a message box(PC)
  19.  
  20.     Select Case ErrorNum
  21.         Case 3196, 3356, 3418
  22.             sMsg = "The Database is in use by another user and cannot be modified.  "
  23.             GoTo dbError_RetryCancel
  24.         Case 3024, 3006
  25.             sMsg = "Database Not Found or is Locked by another user. Application will terminate."
  26.             GoTo dbError_Fatal
  27.         Case 3008, 3009, 3189, 3211, 3212, 3261, 3262
  28.             sMsg = "The record or table is in use and cannot be edited. Changes will not be saved."
  29.             GoTo dbError_RetryCancel
  30.         Case 3014, 3018, 3037
  31.             sMsg = "The record or table you are trying to connect with is corrupt. Please contact tech support"
  32.             GoTo dbError_Fatal
  33.         Case 3021
  34.             sMsg = "There are no records matching the selected criteria"
  35.             GoTo dbError_RetryCancel
  36.         Case 3022
  37.             sMsg = "A duplicate value was found. Please edit first entry rather than create a new entry"
  38.             GoTo dbError_NonFatal
  39.         Case 3058, 3314, 3315
  40.             sMsg = "Please include all required information."
  41.             GoTo dbError_NonFatal
  42.         Case 3070, 3078, 3177, 3184, 3242, 3340
  43.             If Source = "MDIMain" Then
  44.                 sMsg = "Table in the database is not found or corrupt.  The application will terminate"
  45.             Else
  46.                 sMsg = "Table or Query in the database is not found or corrupt."
  47.             End If
  48.             GoTo dbError_Fatal
  49.         Case 3044
  50.             sMsg = ErrorNum & "  " & Err.Description & "  The application will terminate."
  51.             GoTo dbError_Fatal
  52.         Case Else
  53.             sMsg = ErrorNum & "  " & Err.Description & vbCrLf & "An unknown error has occurred. Please notify tech support"
  54.             GoTo dbError_Fatal
  55.     End Select
  56.     Exit Function
  57.     
  58. dbError_RetryCancel:
  59.         Select Case MsgBox(sMsg & vbCrLf & Source, vbRetryCancel)
  60.             Case vbRetry
  61.                 FatalError = False
  62.             Case vbCancel
  63.                 FatalError = True
  64.                 GoTo Exit_FatalError
  65.         End Select
  66.  
  67. dbError_Fatal:
  68.         MsgBox sMsg & vbCrLf & Source
  69.         FatalError = True
  70.         GoTo Exit_FatalError
  71.  
  72. dbError_NonFatal:
  73.         MsgBox sMsg & vbCrLf & Source
  74.         FatalError = False
  75.         GoTo Exit_FatalError
  76.   
  77. Exit_FatalError:
  78.  
  79.     Call LogError(ErrorNum, Source)
  80.  
  81. End Function
  82.  
  83. Private Sub LogError(ErrorNum As Integer, Source As String)
  84.  
  85.     Open App.Path & "\Error.log" For Append As #1
  86.     Seek #1, (LOF(1) + 1)
  87.     Print #1, ErrorNum & "  Source:  " & Source; Tab(15); Err.Description; Tab(25); Format(Now(), "dddd mm/dd/yyyy") _
  88.         ; Tab(49); Format(Now(), "h:mmam/pm");
  89.     Close #1
  90.  
  91. End Sub
  92.